<template>
  <div class="home">
    <div class="jtt-chrome-extension jtt-clearfix" @mouseleave="reset">
      <label class="jtt-label fl">京推推</label>
      <ul class="tab fl jtt-clearfix">
        <li
          class="tab-item fl jtt-vertical-middle"
          :class="{ 'tab-item-hover': activeComponentName == 'commission' }"
          data-index="commission"
          @mouseenter="tabMouseEnter"
        >
          <span class="icon iconfont icon-commission"></span>
          <span class="tab-name"
            >佣金{{
              $store.state.JTTProductInfo.commissionInfo.commissionShare
            }}%</span
          >
        </li>
        <li
          class="tab-item fl jtt-vertical-middle"
          data-index="coupon"
          :class="{ 'tab-item-hover': activeComponentName == 'coupon' }"
          @mouseenter="tabMouseEnter"
        >
          <span class="icon iconfont icon-coupon"></span>
          <span class="tab-name">优惠券</span>
        </li>
        <li
          class="tab-item fl jtt-vertical-middle"
          :class="{ 'tab-item-hover': activeComponentName == 'price' }"
          data-index="price"
          @mouseenter="tabMouseEnter"
        >
          <span class="icon iconfont" :class="calcIcon"></span>
          <span class="tab-name">{{ priceValue }}</span>
        </li>
        <li
          class="tab-item fl jtt-vertical-middle"
          data-index="deliver"
          :class="{ 'tab-item-hover': activeComponentName == 'deliver' }"
          @mouseenter="tabMouseEnter"
        >
          <span class="icon iconfont icon-search"></span>
          <span class="tab-name">全国查货</span>
        </li>
        <li
          class="tab-item fl jtt-vertical-middle"
          data-index="transfer"
          :class="{ 'tab-item-hover': activeComponentName == 'transfer' }"
          @mouseenter="tabMouseEnter"
        >
          <span class="icon iconfont icon-link"></span>
          <span class="tab-name">生成链接</span>
        </li>
        <li
          class="tab-item fl jtt-vertical-middle"
          data-index="compare"
          :class="{ 'tab-item-hover': activeComponentName == 'compare' }"
          @mouseenter="tabMouseEnter"
        >
          <span class="icon iconfont icon-compare"></span>
          <span class="tab-name">同类对比</span>
        </li>
      </ul>

      <div class="tab-content" v-show="activeComponentName">
        <component v-bind:is="activeComponentName"></component>
      </div>
    </div>
  </div>
</template>

<script>
import Commission from "./commission";
import Compare from "./compare";
import Coupon from "./coupon";
import Deliver from "./deliver";
import Price from "./price";
import Transfer from "./transfer";
export default {
  name: "Home",
  components: {
    Commission,
    Compare,
    Coupon,
    Deliver,
    Price,
    Transfer,
  },
  data() {
    return {
      priceValue: "价格平稳",
      activeComponentName: "",
    };
  },
  computed: {
    calcIcon() {
      switch (this.priceValue) {
        case "价格平稳":
          return "icon-price-always"
        case "历史最高":
          return "icon-price-top"
        case "历史最低":
          return "icon-price-lowest"
        case "价格上升":
           return "icon-price-up"
        case "价格下降":
          return "icon-price-down"
      }
    },
  },
  methods: {
    tabMouseEnter(event) {
      this.activeComponentName = event.target.dataset.index;
    },
    reset() {
      this.activeComponentName = "";
    },
  },
  mounted() {
    this.$store.dispatch("jttLMSearch");
    this.$store.dispatch("getPrice").then((res) => {
      const { series_1 } = res;
      let currentPrice = series_1[series_1.length - 1];
      let highPrice = Math.max.apply(null, series_1);
      let lowerPrice = Math.min.apply(null, series_1);
      if (currentPrice == highPrice && currentPrice == lowerPrice) {
        this.priceValue = "价格平稳";
      } else if (currentPrice > highPrice) {
        this.priceValue = "历史最高";
      } else if (currentPrice < lowerPrice) {
        this.priceValue = "历史最低";
      } else if (currentPrice > series_1[series_1.length - 2]) {
        this.priceValue = "价格上升";
      } else if (currentPrice < series_1[series_1.length - 2]) {
        this.priceValue = "价格下降";
      }
    });
    this.$store.dispatch("lmSearch");
  },
};
</script>

<style lang="less" scoped>
.jtt-chrome-extension {
  position: relative;
  margin-bottom: 10px;
  width: 600px;
  height: 32px;
  .jtt-label {
    height: 100%;
    width: 70px;
    background: #f52d36;
    font-size: 14px;
    line-height: 32px;
    font-weight: 400;
    color: #ffffff;
    text-align: center;
  }
  .tab {
    height: 100%;
  }
  .tab-item {
    width: 84px;
    height: 100%;
    border-top: 1px solid #e6e6e6;
    border-bottom: 1px solid #e6e6e6;
    border-right: 1px solid #e6e6e6;
    cursor: pointer;
    text-align: center;
    box-sizing: border-box;
    span {
      display: inline-block;
      vertical-align: middle;
    }
    .icon {
      font-size: 14px;
    }
    .tab-name {
      margin-left: 2px;
      font-size: 12px;
      font-weight: 400;
      color: #434343;
    }
  }
  .tab-item-hover {
    border-top: 2px solid #f52d36;
    border-bottom: none;
    .tab-name {
      color: #f52d36;
    }
    .icon {
      color: #f52d36;
    }
  }
  .tab-content {
    padding: 20px;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 10;
    transform: translateY(100%);
    background: #fff;
    box-sizing: border-box;
    border-left: 1px solid #e6e6e6;
    border-right: 1px solid #e6e6e6;
    border-bottom: 2px solid #f52d36;
    border-radius: 0px 0px 4px 4px;
  }
}
</style>
